package com.qfjy.homework.fanbenpeng;

/**
 * @author:fanbenpeng
 * @date:2022/11/10 19:32
 */

import java.util.List;

/**
 * 两种条件的交集
 */
public class AndCriteria implements Criteria {

    private Criteria criteria;
    private Criteria otherCriteria;

    /**
     * 两种类型进行组合筛选，交集
     * @param criteria 筛选条件
     * @param otherCriteria 额外条件
     */
    public AndCriteria(Criteria criteria, Criteria otherCriteria) {
        this.criteria = criteria;
        this.otherCriteria = otherCriteria;
    }

    /**
     * 两种条件进行组合赛选
     * @param persons 集合
     * @return 返回符合两种条件的集合
     */
    @Override
    public List<Person> meetCriteria(List<Person> persons) {
        List<Person> firstCriteriaPersons = criteria.meetCriteria(persons);
        return otherCriteria.meetCriteria(firstCriteriaPersons);
    }
}
